package com.igeek.utils;

import java.util.List;

/**
 * 分页工具类
 */
public class Page {
    //总共有多少条
    private int total;
    // 每页展示的条数
    private int pageCount;
    //总页数
    private int totalCount;
    //当前码
    private int currentPage;
    //分页后的数据
    private List<?> data;
    //准备一个集合分页工具条
    private int [] bar;

    public Page() {
    }

    public Page(int total, int pageCount, int totalCount, int currentPage, List<?> data) {
        this.total = total;
        this.pageCount = pageCount;
        this.totalCount = totalCount;
        this.currentPage = currentPage;
        this.data = data;
    }

    public Page(int total, int pageCount, int totalCount, int currentPage, List<?> data, int[] bar) {
        this.total = total;
        this.pageCount = pageCount;
        this.totalCount = totalCount;
        this.currentPage = currentPage;
        this.data = data;
        this.bar = bar;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public List<?> getData() {
        return data;
    }

    public void setData(List<?> data) {
        this.data = data;
    }

    public int[] getBar() {
        //确定好开头和结尾
        int start ;
        int stop ;
        //少于10页
        if(totalCount<10){
            start=1;
            stop=totalCount;
        }else{
            start = currentPage -5;
            stop = currentPage +4;
            if(currentPage +4 >= totalCount){
                start = totalCount - 9;
                stop = totalCount ;
            }
            if(currentPage -5 <=0){
                start = 1;
                stop = 10;
            }
        }
        //组织分页条
        bar = new int[stop - start + 1];
        int index = 0;
        for (int i = start; i <= stop; i++) {
            bar[index++] = i;
        }
        return bar;
    }

    public void setBar(int[] bar) {
        this.bar = bar;
    }
}
